package account;

/**
 * Created by cuiyong on 15/7/27.
 */
public class Account {
    private long frozenBlanace;
    private long totalBlance;
    private boolean state = true;

    private PersonalCredit personalCredit = new PersonalCredit(this);

    public void transfer(Account targetAccount, long amount) throws UserStateException, PersonalCreditLimitException {
        checkUserState();

        personalCredit.checkCreditLimit(amount);

        this.totalBlance -= amount;

        targetAccount.balanceAdd(amount);
    }


    public void checkUserState() throws UserStateException {
        if (!state) {
            throw new UserStateException("用户不可用");
        }
    }


    public long getFrozenBlanace() {
        return frozenBlanace;
    }

    public void setFrozenBlanace(long frozenBlanace) {
        this.frozenBlanace = frozenBlanace;
    }

    public long getTotalBlance() {
        return totalBlance;
    }

    public void setTotalBlance(long totalBlance) {
        this.totalBlance = totalBlance;
    }

    public boolean isState() {
        return state;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public Long getNotFrozenBlanace() {
        return totalBlance - frozenBlanace;
    }

    public void balanceAdd(Long amount) {
        this.totalBlance +=amount;
    }
}
